package com.zhentao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.domain.SQuestion;
import com.zhentao.result.Result;
import com.zhentao.service.SQuestionService;
import com.zhentao.mapper.SQuestionMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 86150
* @description 针对表【s_question】的数据库操作Service实现
* @createDate 2024-07-24 09:31:18
*/
@Service
public class SQuestionServiceImpl extends ServiceImpl<SQuestionMapper, SQuestion>
    implements SQuestionService{

    @Resource
    private SQuestionMapper questionMapper;

    //根据课程id查找对应的题目信息
    @Override
    public Result getQuestionBySubjectId(Integer id) {
        List<SQuestion> list=questionMapper.getQuestionBySubjectId(id);
        //把单选和多选的答案拿出来，以便前端处理
        for (SQuestion question:list){
            if (question.getTypeId()==1 || question.getTypeId()==2){
                String question1 = question.getQuestion();
                String[] split = question1.split("/");
                String answer = split[1];
                String[] s = answer.split("_");
                question.setAnswer(s);
            }
        }
        return Result.OK(list);
    }
}




